import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { BusiProvider } from '../../providers/busi/busi';
import { DateTimeUtils } from '../../common/DateTimeUtil';

/**
 * Generated class for the FreeclassroomPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-freeclassroom',
  templateUrl: 'freeclassroom.html',
})
export class FreeclassroomPage {
  freeClassRooms = [];
  startdate: string;
  enddate: string;
  classroomno:string;
  showQueryCtritieria:boolean = true;
  constructor(public navCtrl: NavController, public navParams: NavParams, public busi: BusiProvider) {
    let currentDate = DateTimeUtils.getCurrentDate();
    this.startdate = DateTimeUtils.getIonDateTimeAddHours(currentDate,1);
    this.enddate = DateTimeUtils.getIonDateTimeAddHours(currentDate, 2);
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad FreeclassroomPage');
  }

  ionViewDidEnter(){
   this.getFreeClassRoom();
  }

  getFreeClassRoom() {
    let param = {
      startDate: this.startdate,
      endDate: this.enddate,
      classroomNo:this.classroomno
    }
    this.busi.getFreeClassRooom(param).subscribe(
      data => {
        this.freeClassRooms = data.classroominfo;
      },
      error => {

      }
    );
  }

  query(){
    this.showQueryCtritieria = false;
    this.getFreeClassRoom();
  }

  book(classroomno){
    this.navCtrl.push("BookclassroomPage",{"classroomno":classroomno})
  }

}
